package util;

import javax.sound.midi.Soundbank;

public class Factory {
    //通过指定类型，获取对应的对象
    public static Car getInstance(String carName){
        if (carName.equalsIgnoreCase("bus")) {
            return  new Bus();
        } else if (carName.equalsIgnoreCase("taxi")) {
            return  new Taxi();
        }
        return  null;
    }
    public static void main(String[] args) {
        Car c1 = Factory.getInstance("bus");
        System.out.println(c1.run());
        Car c2 = Factory.getInstance("taxi");
        System.out.println(c2.run());
    }
}
interface  Car{
    String run();
}
class Bus implements  Car{
    @Override
    public String run() {
        return  "bus is running!";
    }
}
class Taxi implements  Car{
    @Override
    public String run() {
        return "taxi is running!";
    }
}
